package top.v5it.japi.plus.log;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import top.v5it.japi.plus.common.util.ServiceDiscoverUtil;

import java.util.Optional;

/**
 * 日志实现注入
 *
 * @author zhanpu
 * @date 2021/3/25
 */
public class OperLogConfigurationSelector implements ImportSelector {

    private final String LOG_CLASS_NAME;

    public OperLogConfigurationSelector() {
        String loadFirstService = ServiceDiscoverUtil.loadFirstService(OperLogService.class, null);
        this.LOG_CLASS_NAME = Optional
                .ofNullable(loadFirstService)
                .orElse(FileWriterOperLogServiceImpl.class.getName());
    }

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        return new String[]{this.LOG_CLASS_NAME};
    }
}
